﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Imaginecup.util.resourceMan;
using imaginecup.util;
using Imaginecup.sprite;
using Imaginecup.sprite.changeSourceSize;

namespace Imaginecup.util
{
    public class DrawNumber:ISourceInfoClass
    {
        private int NUM_SIZEX;
        private int NUM_SIZEY;

        private Vector2 m_NumberSize;

        private EntityInfo m_SourceInfo;
        private ISprite m_Sprite;

        public DrawNumber(String TextureName)
        {
            ChangeSourceSizeSprite changeSprite = new ChangeSourceSizeSprite();
            changeSprite.SetSourceInfoClass(this);
            changeSprite.SetTextureName(TextureName);

            m_Sprite = changeSprite;

            m_SourceInfo = new EntityInfo();

            Vector2 size = ResourceMan.GetResourceMan().GetFrameSize(TextureName);
            EntityInfo textureSize = new EntityInfo(0 , 0 , (int)size.X , (int)size.Y);

            NUM_SIZEX = (int)(textureSize.mSize.X / 10); // 숫자 10개
            NUM_SIZEY = (int)(textureSize.mSize.Y);

            m_NumberSize = new Vector2(NUM_SIZEX, NUM_SIZEY);
        }

  

        public Vector2 GetNumberSize()
        {
            return m_NumberSize;
        }

        private void SetSrcInfo(char num)
        {
            m_SourceInfo.mPosition.Y = 0;
            m_SourceInfo.mSize.X = NUM_SIZEX;
            m_SourceInfo.mSize.Y = NUM_SIZEY;

            switch (num)
            {
                case '1':
                    m_SourceInfo.mPosition.X = 0;
                    break;
                case '2':
                    m_SourceInfo.mPosition.X = NUM_SIZEX;
                    break;
                case '3':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 2;
                    break;
                case '4':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 3;
                    break;
                case '5':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 4;
                    break;
                case '6':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 5;
                    break;
                case '7':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 6;
                    break;
                case '8':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 7;
                    break;
                case '9':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 8;
                    break;
                case '0':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 9;
                    break;
                case '%':
                    m_SourceInfo.mPosition.X = NUM_SIZEX * 10;
                    break;
            }
        }

        public EntityInfo GetSourceInfo()
        {
            return m_SourceInfo;
        }

        public void Draw(SpriteBatch SB, int X, int Y, String number)
        {                        
            EntityInfo entityInfo = new EntityInfo(X, Y, NUM_SIZEX, NUM_SIZEY);

            for (int index = 0; index < number.Length; index++)
            {
                SetSrcInfo(number[index]);
                m_Sprite.Draw(SB, entityInfo);

                entityInfo.mPosition.X += NUM_SIZEX;
            }

        }


    }
}
